// pages/pictureRecognition/pictureRecognition.js
Page({
  data: {
    imageUrl: ''
  },

  previewImage: function() {
    if (this.data.imageUrl) {
      wx.previewImage({
        urls: [this.data.imageUrl],
        current: this.data.imageUrl
      });
    } else {
      wx.showToast({
        title: '请先上传或拍照',
        icon: 'none'
      });
    }
  },

  chooseImage: function() {
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success: (res) => {
        this.setData({
          imageUrl: res.tempFilePaths[0]
        });
      }
    });
  },

  recognizeImage: function() {
    if (this.data.imageUrl) {
      // 这里可以调用图片识别的API
      wx.showToast({
        title: '图片识别中...',
        icon: 'loading'
      });

      // 模拟图片识别
      setTimeout(() => {
        wx.showToast({
          title: '识别完成',
          icon: 'success'
        });
      }, 2000);
    } else {
      wx.showToast({
        title: '请先上传或拍照',
        icon: 'none'
      });
    }
  },

  takePhoto: function() {
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['camera'],
      success: (res) => {
        this.setData({
          imageUrl: res.tempFilePaths[0]
        });
      }
    });
  }
});